'use strict'
//const mongo = require('./mongo');
const mysqlc = require('./mysqlc');
var moment = require('moment');
exports.isExist = function(infohash, funcx) {
  mysqlc.count(infohash,funcx);
    // mongo.bitchina.findByIdAndUpdate(infohash, { $inc: { 'visitCount': 1 }, $set: { 'lastUpdate': moment().format('YYYY-MM-DD') } }, function(err, res) {
    //     if (res != null && res != undefined) {
    //         //console.log('found it');
    //         funcx(true);
    //     } else {
    //         //console.log('not found it');
    //         funcx(false);
    //     }
    // });


};
exports.save = function(btinfo) {
    if (btinfo.name === undefined || btinfo.name === '') {
        console.log("not save 1");
        return;
    }
    if (btinfo.size < 1024) {
        console.log("not save 2");
        return;
    }
    const bean = {
        //_id: btinfo.infohash,
        infohash: btinfo.infohash,
        //magnet: btinfo.magnet,
        name: btinfo.name,
        size: btinfo.size,
        hsize: btinfo.humanSize,
        vcount: btinfo.visitCount,
        isVideo: btinfo.isVideo,
        //address: btinfo.address,
        //port: btinfo.port,
        files: JSON.stringify(btinfo.files),
        createDate: btinfo.createDate,
        lastUpdate: btinfo.lastUpdate,
        createTime: new Date()
    };
    mysqlc.save(bean);
    //new mongo.bitchina(bean).save();
    //console.log("save btinfo :" + promises);
};

exports.increaseVisit = function(infohash) {
    mysqlc.increase(infohash);
};